package day_2022_12_to_3.year2023;

/**
 * @author haomin
 * @date 2023/01/28 22:08
 **/
public class Day1_28_Num1664 {
    class Solution {
        public int waysToMakeFair(int[] nums) {
            int n = nums.length;
            int[] odd = new int[n + 1], even = new int[n + 1];
            for (int i = n - 1; i >= 0; i--) {
                odd[i] = odd[i + 1];
                even[i] = even[i + 1];
                if (i % 2 == 0) even[i] += nums[i];
                else odd[i] += nums[i];
            }

            int ans = 0, a = 0, b = 0;
            for (int i = 0; i < n; i++) {
                if (a + odd[i + 1] == b + even[i + 1]) ans++;
                if (i % 2 == 0) a += nums[i];
                else b += nums[i];
            }
            return ans;
        }
    }
}